package everyday;

import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 金额相关操作
 *
 * @author gaojie
 * @date 2023-07-04
 */
public class MoneyOperation {

    /**
     * 将金额转成数据，便于在打印时显示合同格式
     */
    @Test
    void test01() {
        BigDecimal amount = new BigDecimal("0.10");
        long longValue = amount.multiply(new BigDecimal("100")).longValue();
        final String[] ints = new String[12];

        Map<String, Integer> map = new HashMap<>();
        for (int i = 11; i >= 0; i--) {
            if (longValue != 0) {
                final long l = longValue % 10;
                ints[i] = String.valueOf(l);
                longValue /= 10;
                map.put(String.format("a%d", i + 1), (int) l);
            }
        }
        System.out.println(Arrays.toString(ints));
        System.out.println(map);
    }
}